package cn.nyse.ktc_find.controller;


import wfw.cn.ktc_common.entity.PageResult;
import wfw.cn.ktc_common.entity.Result;
import wfw.cn.ktc_common.entity.ResultCode;
import cn.nyse.ktc_find.entity.Article;
import cn.nyse.ktc_find.service.ArticleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class SearchController {


    @Autowired
    ArticleService articleService;

    @RequestMapping("/search/{keyword}/{page}/{size}")
    public Result searchIndex(@PathVariable String keyword,
                              @PathVariable int page,
                              @PathVariable int size){
        Page<Article> all = articleService.findAll(keyword, page, size);
        return new Result(ResultCode.SUCCESS,new PageResult<Article>(all.getTotalElements(),all.getContent()));
    }
}



